package com.xtwy.admin.web.config.j2cache.autoconfigure;


import com.xtwy.admin.web.config.j2cache.support.J2CacheCacheManger;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.J2Cache;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 开启对spring cache支持的配置入口
 * @author zhangsaizz
 */
//@Configuration
//@ConditionalOnClass(J2Cache.class)
//@EnableConfigurationProperties({ J2CacheExtendConfig.class, CacheProperties.class })
//@ConditionalOnProperty(name = "j2cache.open-spring-cache", havingValue = "true")
//@EnableCaching
//public class J2CacheSpringCacheAutoConfiguration {
//
//    private final CacheProperties cacheProperties;
//
//    private final J2CacheExtendConfig j2CacheExtendConfig;
//
//    J2CacheSpringCacheAutoConfiguration(CacheProperties cacheProperties, J2CacheExtendConfig j2CacheExtendConfig) {
//        this.cacheProperties = cacheProperties;
//        this.j2CacheExtendConfig = j2CacheExtendConfig;
//    }
//
//    @Bean
//    @ConditionalOnBean(CacheChannel.class)
//    public J2CacheCacheManger cacheManager(CacheChannel cacheChannel) {
//        List<String> cacheNames = cacheProperties.getCacheNames();
//        J2CacheCacheManger cacheCacheManger = new J2CacheCacheManger(cacheChannel);
//        cacheCacheManger.setAllowNullValues(j2CacheExtendConfig.isAllowNullValues());
//        cacheCacheManger.setCacheNames(cacheNames);
//        return cacheCacheManger;
//    }
//
//}
